<template>
    <page navbar :scroll="false">
        <router-link to="/" custom v-slot="{ navigate }">
        <div @click="navigate" class="fit-height rp">
            <div class="error404 tc">
                <p class="f40">404 error.</p>
                <p class="f16 mt10">{{$t('找不到请求的页面')}}</p>
                <p class="mt10 gray-1 f12">{{$t('{0} 秒后将跳转至主页').format(displayTime)}}</p>
            </div>
            
            <span class="f18 btnText">{{$t('立即跳转')}}</span>
        </div>
        </router-link>
    </page>
</template>
<script>
import {countDown} from '@/utils/'
import { onBeforeUnmount, ref } from 'vue'
import { useRouter } from 'vue-router'

export default {
    setup(){
        const router = useRouter()
        const displayTime = ref('')
        const timer = countDown(15, {
            format:'ss',
            callback(time){
                displayTime.value = time||''
            },
            finished(){
                router.replace('/home')
            }
        })
        console.log(timer)

        onBeforeUnmount(()=>{
            timer && clearInterval(timer)
        })
        return {
            displayTime
        }
    }
}
</script>
<style lang="less" scoped>
.error404 {
    position: absolute;
    left: 0;
    right: 0;
    top: 30%;
}
.btnText {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0.8rem;
    text-align: center;
}
</style>